<%@page import="accessor.CategoryAccessor"%>
<%@page import="accessor.Category"%>
<%@page import="java.util.List"%>
<%@include file="header.jsp" %>
<%
    CategoryAccessor categoryAccessor = new CategoryAccessor();
    List<Category> list = categoryAccessor.listAllCategories();
    int i=0;
%>
<div id="content">
    <script>
        $(document).ready(function(){
            $("a#del_link").click(function(){
                if(!confirm('are you sure you want to delete this?')){
                    return false;
                }
                var catID = $(this).attr("href");
                var self = $(this);
                $.ajax({
                type:'POST',
                url:"../category_delete",
                data:{'cat_id':catID},
                success:function(data){
                    if(data=='1')
                    {
                        $(self).parent().parent().hide(500);
                    }
                    else{
                        alert(data);
                    }
                }
            });
            return false;
            });
        });
    </script>
    <div id="title_content">Product Category List</div>
    <table class="list" width="100%" cellpadding="0" cellspacing="0">
        <thead>
            <tr>
                <th>ID</th>
                <th>Name</th>
                <th colspan="3" align="center">Action</th>
            </tr>
        </thead>
         <tbody>
        <% for (Category category : list) { %>
        <tr <%= i%2!=1?"style = \"background:#CFF;\"":"style = \"background:#FFFFFF;\"" %>>
            <td><%= category.getCategoryID()%></td>
            <td><%= category.getCategoryName()%></td>
            <td width="30px"><a href="update_category.jsp?catID=<%= category.getCategoryID()%>"><img src="../assets/css/backend/images/modifier.png" alt="modifier"/></a></td>
            <td width="30px">
                <a id="del_link" href="<%= category.getCategoryID()%>">
                    <img src="../assets/css/backend/images/supprimer.png" alt="supprimer"/>
                </a>
            </td>
        </tr>
        <%
            i++;
        }%>
        </tbody>
    </table>
</div>
<%@include file="footer.jsp" %>